<%--
 *  File:    ContactEdit.jsp
 *  @Author: jianni ,KentZhong
 *  Date:    2001/12/10
 *
 *  Copyright (C) 2000 - 2003 Oval Technologies, Inc.
 *  All rights reserved.
 *
 *  This software is the confidential and proprietary information of Oval
 *  Technologies, Inc. ("Confidential Information").  You shall not
 *  disclose such Confidential Information and shall use it only in
 *  accordance with the terms of the license agreement you entered into
 *  with Oval.
--%>


<%@ include file="/inc/SessionTimeout.inc"%>
<%@ page language="java" %>
<%@ page import="java.util.*,
                 java.sql.*,
                 java.util.Date" %>
<%@ page import="org.apache.log4j.Category" %>

<%@ page contentType = "text/html;charset=UTF-8" %>
<%@ taglib uri="/WEB-INF/PageFlow.tld" prefix="PageFlow" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/oval-tag.tld" prefix="oval" %>
<%@ taglib uri="/WEB-INF/custom.tld" prefix="custom" %>
<% //--------------------------------------  setting logger --%>
<%
  	Category cat = Category.getInstance("jsp.ContactEdit");
%>

<% //--------------------------------------  variant and initialization --%>
<%
  	String strModuleName = "OGM";
  	String strPrivCode=(String)request.getParameter("third");
  if( strPrivCode==null)
    strPrivCode=(String)session.getAttribute("third");
  if(strPrivCode==null)
    strPrivCode="";
  String privilegeCode = strPrivCode;
%>



<%
  	boolean bIsNew = false;
  	if(request.getParameter("contactid") == null)
  	{
    	bIsNew = true;
  	}
  	String contactId = new String("");
  	String contactName = new String("");
  	String contactRoleType = new String("");
  	String strEmployeeName = new String("");

    Integer nContactId0 = null;
  	String strContactNameCN = new String("");
  	Integer nContactId1 = null;
  	String strContactNameEN = new String("");

  	Integer nEmployeeId = null;
    Integer parentcontactid = null;
    String parentcontactname = "";

%>

<% //--------------------------------------  include files list --%>
<%@ include file="/inc/Security.inc" %>
<%@ include file="/inc/PageDefault.inc" %>


<html>
<head>
<title>ContactEdit</title>
<PageFlow:CheckPageFlow pageName="contactedit"/>
<%@ include file="/inc/InitEdit.inc" %>
<% //--------------------------------------  output variant from pageflow --%>
<%
	Vector allroletype = (Vector)pageContext.getAttribute("allroletype");
	HashMap contact = null;
	Vector contactNames = (Vector)pageContext.getAttribute("contactnames");
	if(!bIsNew)
	{
		contact = (HashMap)pageContext.getAttribute("contactinfo");
    }

  	if(contactNames==null)
  	{
  		contactNames = new Vector();
  	}

    for(int i = 0;i < contactNames.size();i++)
	{
		HashMap hashTemp = (HashMap)contactNames.elementAt(i);
	    if(((String)hashTemp.get("languagecode")).equalsIgnoreCase("cn"))
	    {
	      	nContactId0 = (Integer)hashTemp.get("contentid");
	      	strContactNameCN = (String)hashTemp.get("content");
	    }
	    if(((String)hashTemp.get("languagecode")).equalsIgnoreCase("en"))
	    {
	      	nContactId1 = (Integer)hashTemp.get("contentid");
	      	strContactNameEN = (String)hashTemp.get("content");
	    }
	}

  	if(allroletype == null)
  	{
    	allroletype = new Vector();
  	}

  	if(contact == null  || contact.isEmpty())
  	{
    	contact = new HashMap();
        parentcontactid = (Integer) pageContext.getAttribute("parentcontactid");
        parentcontactname = (String) pageContext.getAttribute("parentcontactname");
  	}
  	else
  	{
    	contactId = (contact.get("contactid")).toString();
    	contactRoleType = (contact.get("contactroletype")).toString();
    	strEmployeeName = (String)contact.get("employeename");
    	nEmployeeId = (Integer)contact.get("employeeid");
        parentcontactid = (Integer)contact.get("parentcontactid");
        parentcontactname = (String) contact.get("parentcontactname");
  	}

  	String datelastupdated = (new java.sql.Date((new Date()).getTime())).toString();
  	//HashMap contactinfo = (HashMap)pageContext.getAttribute("contactinfo");
  	//if (contactinfo == null)
  	//  contactinfo = new HashMap();


%>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="../../css/<%= strLanguageCode %>/main.css" type="text/css">
<script language="JavaScript" src="../../js/FuncLib.js"></script>
<script language="JavaScript" src="../../js/ScriptLib.js"></script>
<script language="JavaScript">
function page_setEmployee(id,name,gender,email,phone,address)
{
  document.contacteditform.employeeid.value = id;
  document.contacteditform.employeename.value = name;

  document.contacteditform.email.value = email;
  document.contacteditform.officephone.value = phone;

  for(var i=0;i<document.contacteditform.officeaddressid.options.length;i++)
  {
    if(address==document.contacteditform.officeaddressid.options[i].value)
    {
        document.contacteditform.officeaddressid.options[i].selected=true;
        break;
    }
  }

  for(var i=0;i<document.contacteditform.gender.options.length;i++)
  {
    if(gender==document.contacteditform.gender.options[i].value)
    {
        document.contacteditform.gender.options[i].selected=true;
        break;
    }
  }

  var remote = window.open("","newwindow");
  if (remote != null)
    remote.close();
}
  function page_setContact(id,name)
{
  document.contacteditform.parentcontactid.value = id;
  document.contacteditform.parentcontactname.value = name;
  }

function popupselect()
{
  popup('EmployeeSelect.jsp?<%= OvalTools.randomURL() %>&orgid=<%=JspHelper.filterNull( request.getParameter("orgid") )%>&selectopt=valid','newwindow', 'height=250, width=520,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

function popupselect1()
{
  popup('ContactSelect.jsp?<%= OvalTools.randomURL() %>&orgid=<%=JspHelper.filterNull( request.getParameter("orgid") )%>&selectopt=valid','newwindow', 'height=250, width=520,top=100,left=100,toolbar=n0, menubar=no, scrollbars=yes, resizable=no, location=no, status=no');
}

function page_done()
{
  	if(isEmpty(document.contacteditform.gender.value))
    {
        alert('<%=message.getMessageDesc("VALUE_NOT_NULL",  label.getLabelName("L_GenderName",false))%>');
        return;
    }
    if(isEmpty(document.contacteditform.officeaddressid.value))
    {
        alert('<%=message.getMessageDesc("VALUE_NOT_NULL",  label.getLabelName("L_AddressLine1",false))%>');
        return;
    }
      <%if(contactId.length()!=0){%>
         if (document.contacteditform.contactid.value == document.contacteditform.parentcontactid.value){
                  alert('<%=message.getMessageDesc("CAN_NOT_BE_PARENTCONTACTER_OF_ONESELF")%>');
                  return;
         }
        <%}%>
    
    if(!emailCheck(document.contacteditform.email.value,true)&&document.contacteditform.email.value!="")
    {
        alert('<%=message.getMessageDesc("ILLEGAL_FORMAT",  label.getLabelName("L_Email",false))%>');
        return;
    }
 	if(!checkNull(document.contacteditform))
  		return;
  	if(!checkForm(document.contacteditform))
  		return;

	<%if (bIsNew)
	{%>
		MLCSTransform(contacteditform);
	<%}else{%>
		emptyToNull(contacteditform);
	<%}%>
  document.contacteditform.actionname.value = "done";
  isRunning = true;
  document.contacteditform.submit();
}

</script>
</head>

<body>

	<% //--------------------------------------  hidden form variant --%>
	<form name="contacteditform" method="post" action="../../Dispatcher" target="_parent">
    <input type="hidden" name="pagename" value="contactedit">
    <input type="hidden" name="actionname">
    <input type=hidden name=numrows value='<%= ConstantProp.multiLangNumber %>'>
    <input type="hidden" name="datelastupdated" value=<%=JspHelper.filterNull( datelastupdated)%>>
    <input type="hidden" name="orgid" value="<%=JspHelper.filterNull( request.getParameter("orgid") )%>">
<%--    <input type="hidden" name="parentcontactid" value="<%=JspHelper.filterNull( parentcontactid )%>">--%>
    <%if(contactId.length()!=0){%>
    	<input type="hidden" name="contactid" value="<%=JspHelper.filterNull( contactId )%>">
      	<input type="hidden" name="entityid0" value="<%=JspHelper.filterNull( contactId )%>">
      	<input type="hidden" name="entityid1" value="<%=JspHelper.filterNull( contactId )%>">

      	<input type="hidden" name="contentid0" value="<%=JspHelper.filterNull( nContactId0 )%>">
      	<input type="hidden" name="contentid1" value="<%=JspHelper.filterNull( nContactId1 )%>">
  	<%}%>
    <input type="hidden" name="languagecode0" value="<%=JspHelper.filterNull( new String("cn") )%>">
    <input type="hidden" name="languagecode1" value="<%=JspHelper.filterNull( new String("en") )%>">
    <input type="hidden" name="entitytype0" value="<%=JspHelper.filterNull( new String("CN") )%>">
    <input type="hidden" name="entitytype1" value="<%=JspHelper.filterNull( new String("CN") )%>">
    <input type="hidden" name="numrows" value="<%=JspHelper.filterNull( new Integer(2) )%>">

    <input type="hidden" name="cnname">
    <input type="hidden" name="enname">

	<table width="100%" cellspacing="0" border="0" cellpadding="0">
  	<tr>
    	<td>
      		<table width="100%" cellspacing="0" cellpadding="0">
        	<tr>
          		<td colspan="2" class="summary_top"></td>
        	</tr>
        	<tr>
          		<td colspan="2"><img src="../../images/<%= strLanguageCode %>/quote.gif" width="16" height="11">
            		<%= label.getLabelName("L_NEContact") + label.getLabelName("L_Colon") %></td>
        	</tr>
      		</table>

      		<table width="100%" border="1" cellpadding="0" bordercolorlight="#999999" bordercolordark="#FFFFFF" cellspacing="0" align="center">
        	<tr>
          		<td class="need" width="146"> <%= label.getLabelName("L_ContactRoleType") + label.getLabelName("L_Colon") %></td>
          		<td>
            		<select name="contactroletype">
              		<logic:iterate id="allroletypes" collection="<%= allroletype %>">
            		<%
              			HashMap mapTypes = (HashMap)pageContext.getAttribute("allroletypes");
              			String strSelect = "";
              			String tempValue = ((Integer)(mapTypes.get("value"))).toString();
              			if(tempValue.equalsIgnoreCase(contactRoleType))
              			{
                			strSelect = "Selected";
              			}
            		%>
              		<option <%=JspHelper.filterNull( strSelect )%>  value = "<%=JspHelper.filterNull( ((Integer)(mapTypes.get("value"))).toString())%>">
              			<%=JspHelper.filterNull( mapTypes.get("valuename") )%>
              		</option>
            		</logic:iterate>
            		</select>
          		</td>
          		<td class="td-text" width="146"> <%= label.getLabelName("L_EmployeeName") + label.getLabelName("L_Colon") %></td>
          		<td>
              		<input type="hidden" name="employeeid" value="<%=JspHelper.filterNull( nEmployeeId )%>">
              		<input type="text" name="employeename" value="<%=JspHelper.filterNull( strEmployeeName )%>" readonly >
              			<a onclick="popupselect()"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>

          		</td>
        	</tr>
        	<%
          		String strTextTypeCN = "td-text";
          		String strTextTypeEN = "td-text";
          		String strNullCN = "Y";
          		String strNullEN = "Y";
          		if(strLanguageCode.equalsIgnoreCase("cn"))
          		{
            		strTextTypeCN = "need";
            		strNullCN = "N";
            	}
          		if(strLanguageCode.equalsIgnoreCase("en"))
          		{
            		strTextTypeEN = "need";
            		strNullEN = "N";
            	}
        	%>
        	<tr>
			<td width="146" class="need"> <%= label.getLabelName("L_ContactName") + label.getLabelName("L_Colon") %></td>
          		 <td >
						    <custom:hidden name="contactinfo" property="contactlangid"/>
	                        <custom:text name="contactinfo" property="contactname" size="18" command="notnull" module="OGM" label="L_ContactName" needMLC="true" isFirstMLC="true" multiLangType="contactname" entityId="contactid" contentId="contactlangid" colIndex="0"/>
				<a onclick='popup("../../common/Lang.jsp?<%= OvalTools.randomURL() %>&form=contacteditform&module=MD&mlctype=L_ContactName&nativelanguage=need&schema=ovcontactlang&qlname=selectbyid&entityid=<custom:write name="contactinfo" property="contactid"/>&entitytype=contactname&contentid=contactlangid&colindex=0", "newwindow", "height=250, width=320,top=100,left=100,toolbar=n0, menubar=no, scrollbars=no, resizable=no, location=no, status=no");'><custom:button type="3" label="L_Ln" imgsrc="ln.gif" border="0"/></a>
	                        </td>
	                 <td class="td-text"  width="146"> <%= label.getLabelName("L_ContactCode") + label.getLabelName("L_Colon") %></td>
            		        <td><custom:text name="contactinfo" property="contactcode" size="20"/></td>
        	</tr>
        	<%--******************--%>
        	<tr>
          		<td width="146" class="need"> <%= label.getLabelName("L_AddressLine1") + label.getLabelName("L_Colon") %></td>
          		<%String strlabel= message.getMessageDesc("VALUE_NOT_NULL",  label.getLabelName("L_AddressLine1",false)) ;%>
          		<td>
            		<oval:select name="contactinfo" property="officeaddressid" optionsName="alladdress" optionValueKey="addressid" optionInnerTextKey="addressname" defaultValueCost="" defaultValue="------" isnull="N" label="<%=strlabel%>"/>
          		</td>

          		<td class="td-text" width="146"> <%= label.getLabelName("L_Email") + label.getLabelName("L_Colon") %></td>
          		<td>
            		<input type="text" name="email" value='<oval:write name="contactinfo" property="email"/>' size="20" >
          		</td>
        	</tr>
        	<tr>
          		<td width="146" class="need"> <%= label.getLabelName("L_GenderName") + label.getLabelName("L_Colon") %></td>
          		<%String strlabelgender= message.getMessageDesc("VALUE_NOT_NULL",  label.getLabelName("L_GenderName",false)) ;%>

          		<td>
            		<oval:select isnull="N" label="<%=strlabelgender%>" name="contactinfo" property="gender" optionsName="allgender" optionValueKey="value" optionInnerTextKey="valuename" defaultValueCost="" defaultValue="------" />
          		</td>

          		<td class="td-text" width="146"> <%= label.getLabelName("L_OfficePhone") + label.getLabelName("L_Colon") %></td>
          		<td>
            		<input type="text" name="officephone" value='<oval:write name="contactinfo" property="officephone"/>' size="20" >
          		</td>
        	</tr>
        	<tr>
            	<td class="need" width="146"><%= label.getLabelName("L_StatusName") + label.getLabelName("L_Colon") %></td>
                <td colspan=1>
                 <oval:select optionsName="allstatus" optionValueKey="statuscode"  optionInnerTextKey="statusname" name="contactinfo" property="status"/>
                </td>
                <td class="td-text" width="146"> <%= label.getLabelName("L_ParentContact") + label.getLabelName("L_Colon") %></td>
                <td>
<%--            		<input type="text" name="parentcontactname" value='<%=JspHelper.filterNull(parentcontactname)%>' size="20" readonly>--%>
                    <custom:text name="parentcontactinfo" property="contactname" changedName="parentcontactname" size="20" readonly="true"/>
                    <custom:hidden name="parentcontactinfo" property="contactid" changedName="parentcontactid"/>
                   <a onclick="popupselect1()"><custom:button type="3" label="L_Asterisk" imgsrc="flash.gif" border="0"/></a>
               </td>
            </tr>
        	<%--******************--%>
      		</table>
    	</td>
  	</tr>
  	<tr>
    	<td class="summary_top"></td>
  	</tr>

  	<% //--------------------------------------  operation button --%>
  	<tr>
    	<td class="td_center"><a onclick="page_done()"><custom:button type="1" label="L_Finish" imgsrc="finish.gif" border="0" style="width:60"/></a></td>
  	</tr>
	</table>
</form>
</body>
</html>


